package com.cdtu.store.item.controller;

import com.cdtu.store.common.utils.PageUtils;
import com.cdtu.store.common.utils.R;
import com.cdtu.store.common.entity.SpuDetailEntity;
import com.cdtu.store.item.service.SpuDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 
 *
 * @author dongyuhao
 * @email a1059444570@qq.com
 * @date 2020-06-22 19:53:26
 */
@RestController
@RequestMapping("store-item-service/spudetail")
public class SpuDetailController {
    @Autowired
    private SpuDetailService spuDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = spuDetailService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{spuId}")
    public R info(@PathVariable("spuId") Long spuId){
		SpuDetailEntity spuDetail = spuDetailService.getById(spuId);

        return R.ok().put("spuDetail", spuDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SpuDetailEntity spuDetail){
		spuDetailService.save(spuDetail);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuDetailEntity spuDetail){
		spuDetailService.updateById(spuDetail);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] spuIds){
		spuDetailService.removeByIds(Arrays.asList(spuIds));

        return R.ok();
    }

}
